﻿using CrawlerCore;
using CrawlerCore.MinPrice;
using CrawlerCore.XmlData;
using CrawlerCore.XmlDataForeign;
using CrawlerCore.XmlDataTemp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Web;

namespace CrawlerService
{
    public class Crawler : ICrawler
    {
       public RootForeign CrawlerAbacus(int Adults, string ArrivalCode, int Children, DateTime DepartTime, string DepartureCode, int Inf,
            bool IsRoundTrip, DateTime ReturnTime)
        {
            RootForeign rootf = null;
            try
            {
                Abacus abacus = new Abacus();
                SearchInputService searchInput = new SearchInputService(Adults, ArrivalCode, Children, DepartTime, DepartureCode, Inf,
                 IsRoundTrip, ReturnTime,false);
                rootf=abacus.CreateXmlDocument(searchInput);
            }
            catch { }
            return rootf;
        }

        public Root CrawlerVietNamAirlines(int Adults, string ArrivalCode, int Children, DateTime DepartTime, string DepartureCode, int Inf,
            bool IsRoundTrip, DateTime ReturnTime)
        {
            Root root = null;
            try
            {
                SearchInputService searchInput = new SearchInputService(Adults, ArrivalCode, Children, DepartTime, DepartureCode, Inf,
             IsRoundTrip, ReturnTime,false);
                VietnamAirlines vietnamAirlines = new VietnamAirlines();
                root= vietnamAirlines.CreateXmlDocument(searchInput);
            }
            catch
            {

            }
            return root;
        }
        public Root CrawlerVietJetAir(int Adults, string ArrivalCode, int Children, DateTime DepartTime, string DepartureCode, int Inf,
            bool IsRoundTrip, DateTime ReturnTime)
        {
            Root root = null;
            try
            {
                SearchInputService searchInput = new SearchInputService(Adults, ArrivalCode, Children, DepartTime, DepartureCode, Inf,
             IsRoundTrip, ReturnTime,false);
                VietJetAir vietJetAir = new VietJetAir();
                root= vietJetAir.CreateXmlDocument(searchInput);
            }
            catch
            {

            }
            return root;
        }
        public Root CrawlerJetstar(int Adults, string ArrivalCode, int Children, DateTime DepartTime, string DepartureCode, int Inf,
            bool IsRoundTrip, DateTime ReturnTime)
        {
            Root root = null;
            try
            {
                SearchInputService searchInput = new SearchInputService(Adults, ArrivalCode, Children, DepartTime, DepartureCode, Inf,
             IsRoundTrip, ReturnTime,false);
                Jetstar jetstar = new Jetstar();
                root= jetstar.CreateXmlDocument(searchInput);
            }
            catch
            { }
            return root;
        }


        public RootMinPrice GetPriceInFareVietJetAir(int Adults, string ArrivalCode, int Children, DateTime DepartTime, string DepartureCode, int Inf, bool IsRoundTrip, DateTime ReturnTime)
        {
            SearchInputService searchInput = new SearchInputService(Adults, ArrivalCode, Children, DepartTime, DepartureCode, Inf,
             IsRoundTrip, ReturnTime, true);
            VietJetAir vietJetAir = new VietJetAir();
            return vietJetAir.GetPriceInFare(searchInput);
        }


        public RootMinPrice GetPriceInFareJetstar(int Adults, string ArrivalCode, int Children, DateTime DepartTime, string DepartureCode, int Inf, bool IsRoundTrip, DateTime ReturnTime)
        {
            SearchInputService searchInput = new SearchInputService(Adults, ArrivalCode, Children, DepartTime, DepartureCode, Inf,
             IsRoundTrip, ReturnTime, true);
            Jetstar jetstar = new Jetstar();
            return jetstar.GetPriceInFare(searchInput);
        }


        public RootMinPrice GetPriceInFareVietNamAirlines(int Adults, string ArrivalCode, int Children, DateTime DepartTime, string DepartureCode, int Inf, bool IsRoundTrip, DateTime ReturnTime)
        {
            SearchInputService searchInput = new SearchInputService(Adults, ArrivalCode, Children, DepartTime, DepartureCode, Inf,
             IsRoundTrip, ReturnTime, true);
            VietnamAirlines vietnamAirlines = new VietnamAirlines();
            return vietnamAirlines.GetPriceInFare(searchInput);
        }

        public RootForeign CrawlerTigerair(int Adults, string ArrivalCode, int Children, DateTime DepartTime, string DepartureCode, int Inf,
            bool IsRoundTrip, DateTime ReturnTime)
        {
            SearchInputService searchInput = new SearchInputService(Adults, ArrivalCode, Children, DepartTime, DepartureCode, Inf,
             IsRoundTrip, ReturnTime, true);
            Tigerair bl = new Tigerair();
            return bl.CreateXmlDocument(searchInput).Convert2RootForeign(searchInput.IsRoundTrip);
        }


        public RootForeign CrawlerVietJetAirForeign(int Adults, string ArrivalCode, int Children, DateTime DepartTime, string DepartureCode, int Inf, bool IsRoundTrip, DateTime ReturnTime)
        {
            try
            {
                Root root = null;
                SearchInputService searchInput = new SearchInputService(Adults, ArrivalCode, Children, DepartTime, DepartureCode, Inf,
             IsRoundTrip, ReturnTime, false);
                VietJetAir vietJetAir = new VietJetAir();
                root = vietJetAir.CreateXmlDocument(searchInput);
                return root.Convert2RootForeign(searchInput);
            }
            catch
            {
            }
            return null;
        }
        public RootForeign CrawlerAirAsia(int Adults, string ArrivalCode, int Children, DateTime DepartTime, string DepartureCode, int Inf, bool IsRoundTrip, DateTime ReturnTime)
        {
            RootForeign rootf = null;
            try
            {
                AirAsia airAsia = new AirAsia();
                SearchInputService searchInput = new SearchInputService(Adults, ArrivalCode, Children, DepartTime, DepartureCode, Inf,
                 IsRoundTrip, ReturnTime, false);
                rootf = airAsia.CreateXmlDocument(searchInput).Convert2RootForeign(searchInput.IsRoundTrip);
            }
            catch { }

            return rootf;
        }
    }
}
